package thread_01;

import java.util.concurrent.Semaphore;

public class Demo42 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore =new Semaphore(4);
        semaphore.acquire();
        System.out.println("p操作");
        semaphore.acquire();
        System.out.println("p操作");
        semaphore.acquire();
        System.out.println("p操作");
        semaphore.acquire();
        System.out.println("p操作");
//        只执行4次操作，第五次阻塞等待，其他线程执行v操作为止
        semaphore.acquire();
        System.out.println("p操作");
    }

}
